/**
 * 对象去重
 */
export function $sunDelId(data, field = 'id') {
  const hash = {}
  const dataArray = data.reduce((preVal, curVal) => {
    hash[curVal[field]]
      ? ''
      : (hash[curVal[field]] = true && preVal.push(curVal))
    return preVal
  }, [])
  return dataArray
}

// 设置Children下的label value
export function $sunSetChildrenVL(data, key, label_len = 99999) {
  data?.forEach((el) => {
    el['value'] = JSON.stringify(el.id)
    el['label'] = el[key].substring(0, label_len)
    el.children && el.children.length > 0 ? $sunSetChildrenVL(el.children, key) : delete el.children
  })
  return data
}
